//
//  ReachabilityHandler.swift
//  TestWorkSpace
//
//  Created by 计海峰 on 2020/1/7.
//  Copyright © 2020 jhf. All rights reserved.
//

import Foundation
import Reachability

class ReachabilityHandler {
    
    static let shared = ReachabilityHandler()
    
    lazy var reachability: Reachability = {
        let reachability = try! Reachability()
        reachability.whenReachable = { reachability in
            if reachability.connection == .wifi {
                print("Reachable via WiFi")
            } else {
                print("Reachable via Cellular")
            }
        }
        reachability.whenUnreachable = { _ in
            print("Not reachable")
        }
        return reachability
    }()
    
    func startNotifier() {
        do {
            try reachability.startNotifier()
        } catch {
            print("Unable to start notifier")
        }
    }
    
    func stopNotifier() {
        reachability.stopNotifier()
    }
    
}
